$(function(){
    obj.init();
});

var obj = new JsFun();
function JsFun() {
    'use strict';
    return {
        dataGrid: null,
        params: {
            schoolIds: null
        },
        dom: {
            confirm: null,
            search: null
        },
        init: function () {
            this.params.schoolIds = xhTool.getQuery('schoolIds');

            this.dataGrid = new xhDataGrid($('#list'), 'Track/getSchoolOffer', {schoolIds: this.params.schoolIds});
            this.dataGrid.parseToolbar().init();

            this.dom.confirm = window.top.xhTop.getModalConfirmDom();
            this.dom.search  = $('#bt_list_search');

            this.listener();
        },
        listener: function () {
            var $this = this;
            //确认按钮
            $this.dom.confirm.click(function() {
                $this.funObj().confirmOffer();
            });
            //查询按钮
            $this.dom.search.click(function (){
                $this.funObj().search();
            });
            xhTool.bindDocKeyDown($this.dom.search);
        },
        funObj: function() {
            var $this = this;
            return {
                confirmOffer: function() {
                    var ids     = $this.dataGrid.getSelectValues('iUserId');
                    var names   = $this.dataGrid.getSelectValues('sUserName');
                    if (ids) {
                        ids = ids.join(',');
                    }
                    if (names) {
                        names = names.join(',');
                    }
                    window.top.xhTop.getActiveFrame().setOfferInfo(ids, names);
                    window.top.xhTop.closeModal();
                },
                search: function () {
                    $this.dataGrid.reload({
                        search: {
                            vague: xhExtra.getValue($('#list_search')),
                            sLogonName:xhExtra.getValue($('#login_name')),
                        }
                    })
                }
            }
        }
    }
}